home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_6.zip
/
EDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-01
|
24KB
|
823 lines
/*
GWAda Development Environment for 386/486 PCs
Copyright (C) 1993, Arthur Vargas Lopes & Michael Bliss Feldman
vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* edit.c */
#include "externs.h"
int AVL_COL()
{
AVL_EDIT_WINDOW_PTR w;
int i, j = 0, n, n2 = 0;
char *t, line [30];
w = &avl_windows[avl_window];
t = w -> current_line -> line;
n = strlen(t);
for(i = 0; i <= w -> txt_col; ++i) {
if (*(t + i) == '\t' && i != w -> txt_col) {
for (n2= 0; !(((j + 1) % w -> tabsize) == 0); ++n2)
j++;
j++;
}
else
j++;
}
return j;
}
void AVL_JOIN_RIGHT() /* Join current line with next */
{
AVL_EDIT_WINDOW_PTR w;
AVL_LINE_PTR temp, temp2;
struct rccoord old;
int pos, pos2;
w = &avl_windows[avl_window];
if (w -> current_line -> next != w -> head) {
pos2 = w -> txt_col;
if ((strlen(w -> current_line -> line) + strlen(w -> current_line -> next -> line)) >= AVL_MAX_LINEL) {
AVL_ERROR("Lines are too long. Can't perform join!");
return;
}
if (w -> scr_row < (w -> r2 - w -> r1 + 1)) {
old = _settextposition(w -> scr_row+1,w -> scr_col);
AVL_DELETE_LINE();
}
else
old = _settextposition(w -> scr_row,w -> scr_col);
temp = w -> current_line -> next;
strcat(w -> current_line -> line,temp -> line);
w -> current_line -> next = temp -> next;
temp -> next -> previous = w -> current_line;
AVL_MAKE_NUMBER();
free(temp);
pos = w -> scr_row;
temp = temp2 = w -> current_line;
while (++pos != (w -> r2 - w -> r1 + 1) && temp -> next != w -> head) {
temp = temp -> next;
}
if (pos == (w -> r2 - w -> r1 + 1) && temp != w -> head) {
w -> current_line = temp;
w -> scr_row = w -> r2 - w -> r1 + 1;
_settextposition( w -> scr_row, 1);
AVL_UPDATE_LINE();
}
w -> current_line = temp2;
old = _settextposition(w -> scr_row = old.row,w -> scr_col = old.col);
w -> txt_col = pos2;
w -> changed = 1;
AVL_UPDATE_LINE();
}
}
void AVL_JOIN_LEFT() /* Join current line with Previos */
{
AVL_EDIT_WINDOW_PTR w;
AVL_LINE_PTR temp, temp2;
struct rccoord old;
int pos, pos2;
w = &avl_windows[avl_window];
if (w -> current_line -> previous != w -> head) {
if ((strlen(w -> current_line -> line) + strlen(w -> current_line -> previous -> line)) >= AVL_MAX_LINEL) {
AVL_ERROR("Lines are too long. Can't perform join!");
return;
}
old = _settextposition(w -> scr_row+1,w -> scr_col);
temp = w -> current_line;
w -> current_line = w -> current_line -> previous;
AVL_CURSOR_END();
pos2 = w -> txt_col;
strcat(w -> current_line -> line, temp -> line);
w -> current_line -> next = temp -> next;
temp -> next -> previous = w -> current_line;
AVL_MAKE_NUMBER();
free(temp);
if (w -> scr_row != 1)
AVL_DELETE_LINE();
pos = w -> scr_row;
temp = temp2 = w -> current_line;
while (++pos != (w -> r2 + 1) && temp -> next != w -> head) {
temp = temp -> next;
}
if (pos == (w -> r2 + 1) && temp != w -> head) {
w -> current_line = temp;
w -> scr_row = (w -> r2 - 1);
_settextposition( (w -> r2 - 1), 1);
AVL_UPDATE_LINE();
}
w -> current_line = temp2;
if (old.row > 1)
old = _settextposition(w -> scr_row = old.row - 1,w -> scr_col = old.col);
else
old = _settextposition(w -> scr_row = old.row,w -> scr_col = old.col);
w -> txt_col = pos2;
AVL_UPDATE_LINE();
w -> changed = 1;
}
}
int AVL_OFFSET()
{
AVL_EDIT_WINDOW_PTR w;
int n, i, off = 0;
w = &avl_windows[avl_window];
n = AVL_COL();
off = 0;
for(i = (w -> c2 - w -> c1 + 1); i < n; i += 20)
off += 20;
return ( off );
}
int AVL_COUNT()
{
int i = 0;
AVL_EDIT_WINDOW_PTR w;
w = &avl_windows[avl_window];
avl_line_temp = w -> current_line;
for (; avl_line_temp != w -> head
&& i < w -> r2; avl_line_temp = avl_line_temp -> next)
++i;
avl_line_temp = avl_line_temp -> previous;
return i;
}
void AVL_OPEN_LINE()
{
short left, top, right, bottom;
struct rccoord rc;
_gettextwindow( &top, &left, &bottom, &right );
rc = _gettextposition();
_settextwindow( rc.row+1, left, bottom, right );
_scrolltextwindow( _GSCROLLDOWN );
_settextwindow( top, left, bottom, right );
_settextposition( rc.row+1, rc.col );
}
void AVL_EDIT_ENTER()
{
AVL_EDIT_WINDOW_PTR w;
AVL_LINE_PTR temp;
struct rccoord old;
short i, j, k;
old = _gettextposition();
w = &avl_windows[avl_window];
for(i = 0, j = 0; w -> current_line -> line [i] == ' '; ++i);
j = i;
temp = calloc(1,sizeof(AVL_LINE_SIZE));
temp -> previous = w -> current_line;
temp -> next = w -> current_line -> next;
w -> current_line -> next -> previous = temp;
w -> current_line -> next = temp;
strcpy(temp -> line, w -> current_line -> line + w -> txt_col);
w -> current_line -> line [w -> txt_col] = '\0';
AVL_MAKE_NUMBER();
w -> txt_col = 0;
AVL_OPEN_LINE();
_settextposition(w -> scr_row,w -> scr_col = 1);
AVL_UPDATE_LINE();
if (w -> scr_row == (w -> r2 - w -> r1 + 1))
_scrolltextwindow( 1 );
else
w -> scr_row += 1;
w -> current_line = temp;
w -> changed = 1;
if (strlen(temp -> line) > 0)
j = 0;
for(i = 0; i < j; ++i)
w -> current_line -> line[i] = ' ';
if (j > 0)
w -> current_line -> line[i] = '\0';
_settextposition(w -> scr_row,w -> scr_col = (j < 78) ? j + 1 : 1);
w -> txt_col = (j < 78) ? j : 0;
AVL_UPDATE_LINE();
if (w -> offset != 0) {
w -> offset = 0;
AVL_SCROLL();
}
}
void AVL_SCROLL()
{
AVL_EDIT_WINDOW_PTR w;
AVL_LINE_PTR temp;
struct rccoord old;
short i, j, k;
AVL_WIN_PTR t, t2;
w = &avl_windows[avl_window];
old = _gettextposition();
temp = w -> current_line;
j = old.row;
/*
if ((w -> txt_col == strlen(temp -> line)) && (w -> txt_col > 0))
w -> txt_col -= 1;
*/
k = w -> txt_col;
for(i = j; i > 1; --i) {
w -> current_line = w -> current_line -> previous;
}
w -> scr_row = 1;
avl_hscroll_on = 1;
_settextposition(1,1);
AVL_UPDATE_SCREEN();
_settextposition(old.row,old.col);
w -> current_line = temp;
w -> scr_row = j;
w -> scr_col = old.col;
w -> txt_col = k;
avl_hscroll_on = 0;
AVL_UPDATE_CURSOR();
}
void AVL_UPDATE_STATUS_LINE()
{
AVL_EDIT_WINDOW_PTR w;
char status[10];
char line[181];
char fn[121];
short att, attold;
short i, n;
char *p;
w = &avl_windows[avl_window];
attold = _gettextcursor();
if (w -> no_status == 'N') return;
if (avl_window < AVL_MAX_WINDOWS)
switch (tolower(w -> edit_mode)) {
case 'x' : strcpy(status,"Ovr"); att = 0x0007; break;
case 'i' : strcpy(status,"Ins"); att = 0x0707; break;
default : w -> edit_mode = 'i'; strcpy(status,"Ins"); att = 0x0707; break;
}
else
strcpy(status,"Hlp");
AVL_MAKE_FN(fn, w -> file_name);
sprintf(line,"Line %3d Col %2d %-35s %s %-12s F1-Help "
, w -> current_line -> line_no - 1
, w -> txt_col + 1
, avl_message
, status
, fn
);
n = strlen(line);
if (n > 80) n = 80;
p = line;
for(i = 1; i <= n; ++i, ++p)
/* AVL_PUT(*p,w -> r1 - 1,i,avl_sta_bk_color,avl_sta_color); */
AVL_WVIDEO(*p,(unsigned char) (avl_sta_bk_color << 4 | avl_sta_color)
, AVL_MAP(w -> r1 - 1,i));
if (attold != att)
_settextcursor(att);
}
void AVL_INIT_WINDOW(AVL_EDIT_WINDOW_PTR w, AVL_LINE_PTR first)
{
short att;
att = _settextcursor(0x